import updateManager from './common/updateManager';

App({
  globalData: {
    roomId: null,
  },
  onLaunch: function (options) {
    // 尝试从缓存中恢复包厢号
    const storedRoomId = wx.getStorageSync('roomId');
    if (storedRoomId) {
      this.globalData.roomId = storedRoomId;
      console.log(`[INFO] Restored room ID from storage: ${storedRoomId}`);
    }

    // 检查是否通过扫码进入，扫码的优先级更高
    if (options && options.query && options.query.room) {
      const newRoomId = options.query.room;
      this.globalData.roomId = newRoomId;
      wx.setStorageSync('roomId', newRoomId); // 同时保存到缓存
      console.log(`[INFO] Launched with new room ID: ${newRoomId}`);
    }
  },
  onShow: function () {
    updateManager();
  },
});
